package activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.VolleyError;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.RecognizerResult;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechUtility;
import com.iflytek.cloud.ui.RecognizerDialog;
import com.iflytek.cloud.ui.RecognizerDialogListener;
import com.qzhy.female.R;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMVideo;
import com.umeng.socialize.media.UMusic;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;

import Constant.Constance;
import adapter.post_img_adapter;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import dilog.RewardsDialog;
import iflyvoice.JsonParser;
import model.Comment;
import model.Image;
import model.UserArticle;
import model.UserArticle_Result;
import utils.GsonUtils;
import utils.HTTPUtils;
import utils.SetUtils;
import utils.UILUtils;
import volley.VolleyListener;
import widget.PasteEditText;

public class PostDetailActivity extends BaseActivity implements OnClickListener {

	private ListView mListImg;
	private post_img_adapter post_img_adapter;
	private ListView mListOtherPost;
	private detail_other_post detail_other_post;
	private LinearLayout mLlPost;
	private ImageView mImgBack;
	private ArrayList<Image> mArticleImg=new ArrayList<Image>();
	private ArrayList<Comment> mOtherComment=new ArrayList<Comment>();
	private ArrayList<Comment> mComment=new ArrayList<Comment>();
	private HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();
	private TextView mTvName;
	private ImageView mImgPhoto;
	private TextView mTvContent;
	private ScrollView srcollViewEx;
	private Integer articleId;
	private TextView mTvShare;
	private TextView mTvCollect;
	private TextView mTvRewards;
	private TextView mTvPraise;
	private int NumPraise;
	private View share_view;
	private LinearLayout mLlCancle;
	private RelativeLayout mRtlCancle;
	private TextView mTvWb;
	private TextView mTvQq;
	private TextView mTvQqzone;
	private TextView mTvWx;
	private boolean IsPraise=true;// ture 没有点赞过   false 点赞过
	private boolean IsCollect=true;// ture 没有收藏过   false 收藏过
	private String Zaned;
	private model.Praise praise;
	private Integer userId;
	private String shareContent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_post_detai);
		SpeechUtility.createUtility(this, SpeechConstant.APPID + "=5628aaa4");
		InitUI();
		GetDate();
		GetPraiseStatus();
		GetCollectStatus();
		InitListImg();
		InitOtherPost();
	}
	private void GetCollectStatus() {
		HTTPUtils.get(this, Constance.URL.POST_ARTICLE+"/"+articleId+"/user/"+SetUtils.GetUserId(this)+"/iscollect", new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
				model.Praise collected = GsonUtils.parseJSON(arg0, model.Praise.class);
				if(collected.getStatus().equals(Constance.STATUS_TYPE.ERROR)){
					IsCollect=false;
					Drawable collect=getResources().getDrawable(R.drawable.ic_collects);  
					collect.setBounds(0, 0, collect.getMinimumWidth(), collect.getMinimumHeight());
					mTvCollect.setCompoundDrawables(null, collect, null, null);
				}else {
					IsCollect=true;
				}
			}
			@Override
			public void onErrorResponse(VolleyError arg0) {
				showToast("收藏解析失败");
			}
		});
	}

	private void GetPraiseStatus() {
		HTTPUtils.get(this, Constance.URL.POST_ARTICLE+"/"+articleId+"/user/"+SetUtils.GetUserId(this)+"/ispraise", new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
//				showToast(arg0.toString());
				praise = GsonUtils.parseJSON(arg0, model.Praise.class);
				Zaned=praise.getStatus();
				if(praise.getStatus().equals(Constance.STATUS_TYPE.ERROR)){
					IsPraise=false;
//					showToast("您已经点过赞了");
					Drawable Praised=getResources().getDrawable(R.drawable.ic_praises);  
					Praised.setBounds(0, 0, Praised.getMinimumWidth(), Praised.getMinimumHeight());
					mTvPraise.setCompoundDrawables(null, Praised, null, null);
				}else {
					IsPraise=true;
				}
			}
			
			@Override
			public void onErrorResponse(VolleyError arg0) {
			}
		});
	}

	private void GetDate() {
		showLoadingDialog();
		GetPostDetail();
	}
	private UserArticle_Result result;
	private UMImage image;
	private UMusic music;
	private UMVideo video;
	
	private void GetPostDetail() {
		Intent intent = getIntent();
		articleId = intent.getIntExtra("AriticleId",0);
		HTTPUtils.get(this, Constance.URL.POST_ARTICLE+"/"+articleId, new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
				UserArticle userArticle = GsonUtils.parseJSON(arg0, UserArticle.class);
				String status = userArticle.getStatus();
				if(status.equals("success")){
					dismissLoadingDialog();
					result = userArticle.getResult();
					userId = result.getUserId();
					shareContent=result.getContent();
					mTvName.setText(result.getUser().getNickname());
					UILUtils.displayImageNoAnim(Constance.URL.IMG_BASE+"/"+result.getUser().getProfileImg(), mImgPhoto);
					mTvContent.setText(result.getContent());
					mArticleImg.clear();
					mOtherComment.clear();
					mComment.clear();
					articleId= result.getId();
					NumPraise= result.getPraise();
					mTvPraise.setText("点赞+"+NumPraise);
					mArticleImg.addAll(result.getImages());
					mOtherComment.addAll(result.getComments());
					post_img_adapter.notifyDataSetChanged();
					detail_other_post.notifyDataSetChanged();
//					srcollViewEx.smoothScrollTo(0, 0);
				}
			}
			@Override
			public void onErrorResponse(VolleyError arg0) {
				Toast.makeText(PostDetailActivity.this,"VolleyError", 1).show();
			}
		});
	}
	private void InitUI() {
		share_view = findViewById(R.id.share);
		mRtlCancle = (RelativeLayout) findViewById(R.id.rtl_cancle);
		mRtlCancle.setOnClickListener(this);
		mLlCancle = (LinearLayout) findViewById(R.id.ll_cancle);
		mLlCancle.setOnClickListener(this);
		mLlPost = (LinearLayout) findViewById(R.id.ll_post);
		mTvShare = (TextView) findViewById(R.id.tv_share);
		mTvCollect = (TextView) findViewById(R.id.tv_user_collect);
		mTvRewards = (TextView) findViewById(R.id.tv_rewards);
		mTvPraise = (TextView) findViewById(R.id.tv_praise);
		mImgBack = (ImageView) findViewById(R.id.img_back);
		mTvWb = (TextView) findViewById(R.id.tv_wb);
		mTvQq = (TextView) findViewById(R.id.tv_qq);
		mTvQqzone = (TextView) findViewById(R.id.tv_qqzone);
		mTvQqzone.setOnClickListener(this);
		mTvWx = (TextView) findViewById(R.id.tv_wx);
		mTvCollect.setOnClickListener(this);
		mTvWx.setOnClickListener(this);
		mTvQq.setOnClickListener(this);
		mTvWb.setOnClickListener(this);
		mTvShare.setOnClickListener(this);
		mTvPraise.setOnClickListener(this);
		mTvRewards.setOnClickListener(this);
		mLlPost.setOnClickListener(this);
		mImgBack.setOnClickListener(this);
		mTvName = (TextView) findViewById(R.id.tv_name);
		mImgPhoto = (ImageView) findViewById(R.id.img_photo);
		mImgPhoto.setOnClickListener(this);
		mTvContent = (TextView) findViewById(R.id.tv_content);
		srcollViewEx = (ScrollView) findViewById(R.id.refreshScrollView);
		mEtInput = (PasteEditText) findViewById(R.id.et_input);
		mTvSend = (TextView) findViewById(R.id.tv_send);
		mTvSend.setOnClickListener(this);
		mTvVoice = (TextView) findViewById(R.id.tv_voices);
		mTvVoice.setOnClickListener(this);
	}

	private void InitOtherPost() {
		mListOtherPost = (ListView) findViewById(R.id.list_other_post);
		detail_other_post = new detail_other_post(this,this,mOtherComment,mEtInput,mTvSend);
		mListOtherPost.setAdapter(detail_other_post);
	}
	private void InitListImg() {
		mListImg = (ListView) findViewById(R.id.list_img);
		post_img_adapter = new post_img_adapter(this,mArticleImg);
		mListImg.setAdapter(post_img_adapter);
	}

	@Override
	public void onClick(View v) {
		image = new UMImage(PostDetailActivity.this, "http://www.umeng.com/images/pic/social/integrated_3.png");
        music = new UMusic("http://music.huoxing.com/upload/20130330/1364651263157_1085.mp3");
        music.setTitle("sdasdasd");
        music.setThumb(new UMImage(PostDetailActivity.this,"	"));
        video = new UMVideo("http://video.sina.com.cn/p/sports/cba/v/2013-10-22/144463050817.html");
		switch (v.getId()) {
		case R.id.ll_post:
			if(SetUtils.islogined(this)){
				Intent intent = new Intent(PostDetailActivity.this,RepliesActivity.class);
				Log.i("文章id", ""+articleId);
				intent.putExtra(Constance.INTENT.ARTICLE_ID, articleId);
				intent.putExtra(Constance.INTENT.REPLIES, 2);
				startActivityForResult(intent, Constance.INTENT.REPLIES_RESULT);
			}else {
				startActivity(new Intent(this,LoginActivity.class));
			}
		   break;
		case R.id.img_back:
			finish();
			break;
		case R.id.tv_praise:
			if(IsPraise){
				Praise();
			}else {
				CanclePraise();
			}
			break;
		case R.id.tv_share:
			Share();
			break;
		case R.id.ll_cancle:
			share_view.setVisibility(View.INVISIBLE);
			break;
		case R.id.rtl_cancle:
			share_view.setVisibility(View.INVISIBLE);
			break;
		case R.id.tv_wb:
			ShareWb();
			break;
		case R.id.tv_qq:
			new ShareAction(this).setPlatform(SHARE_MEDIA.QQ).setCallback(umShareListener)
	         .withText("hello umeng")
	         .withMedia(music)
	         .withTitle("qqshare")
	         .withTargetUrl("http://dev.umeng.com")
	         .share();
			 share_view.setVisibility(View.GONE);
			break;
		case R.id.tv_qqzone:
			ShareQqzone();
			break;
		case R.id.tv_wx:
			ShareWx();
			break;
		case R.id.tv_user_collect:
			if(IsCollect){
				Collecting();
			}else {
				CancleCollect();
			}
			break;
		case R.id.img_photo:
			Intent intent = new Intent(PostDetailActivity.this,MineActivity.class);
			intent.putExtra(Constance.INTENT.USER_ID, userId);
			startActivity(intent);
			break;
		case R.id.tv_rewards:
			ReWards();
			break;
		case R.id.tv_send:
			Replies();
			Toast.makeText(this, "回复楼主", 1).show();
			break;
		case R.id.tv_voices:	
			Voice();
			break;
		default:
			break;
		}
	}
	/**
	 * 语音模式
	 */
	private void Voice() {
		// 1.创建RecognizerDialog对象
		RecognizerDialog mDialog = new RecognizerDialog(
				PostDetailActivity.this, mInitListener);
		// 2.设置accent、language等参数
		mDialog.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
		mDialog.setParameter(SpeechConstant.ACCENT, "mandarin");
		// 3.设置回调接口
		mDialog.setListener(mRecognizerDialogListener);
		// 4.显示dialog，接收语音输入
		mDialog.show();
	}
	private RecognizerDialogListener mRecognizerDialogListener = new RecognizerDialogListener() {

		@Override
		public void onResult(RecognizerResult arg0, boolean arg1) {
			String text = JsonParser.parseIatResult(arg0.getResultString());
			System.out.println("text" + text);
			String sn = null;
			// 读取json结果中的sn字段
			try {
				JSONObject resultJson = new JSONObject(arg0.getResultString());
				sn = resultJson.optString("sn");
				System.out.println("sn" + sn);
			} catch (JSONException e) {
				e.printStackTrace();
			}

			mIatResults.put(sn, text);

			StringBuffer resultBuffer = new StringBuffer();
			for (String key : mIatResults.keySet()) {
				resultBuffer.append(mIatResults.get(key));
			}
			mEtInput.setText(resultBuffer.toString());
		}

		@Override
		public void onError(SpeechError arg0) {

		}
	};
	/**
	 * 初始化监听器。
	 */
	private InitListener mInitListener = new InitListener() {

		@Override
		public void onInit(int code) {
		}
	};
	private void Replies() {
		showLoadingDialog();
		Map<String, String> params=new HashMap<String,String>();
		params.put("user_id",""+SetUtils.GetUserId(this));
		params.put("article_id",""+articleId);
		params.put("parent_comment_id", ""+0);
		params.put("content", mEtInput.getText().toString().trim());
		HTTPUtils.post(this, Constance.URL.REPLY_POST, params, new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
				Toast.makeText(PostDetailActivity.this, "onResponse"+arg0.toString(), 1).show();
				if(arg0!=null){
					dismissLoadingDialog();
					Toast.makeText(PostDetailActivity.this, "回贴成功",1).show();
					GetPostDetail();
					srcollViewEx.measure(0, 0);
					mListImg.measure(0, 0);
					mListOtherPost.measure(0, 0);
					int height=srcollViewEx.getHeight()+mListImg.getHeight()+mListOtherPost.getHeight()+100;
					srcollViewEx.scrollTo(0,height);  
					srcollViewEx.smoothScrollTo(0, height); 
				}
			}
			@Override
			public void onErrorResponse(VolleyError arg0) {
				Toast.makeText(PostDetailActivity.this, "解析错误",1).show();
			}
		});
	}
	/**
	 * 打赏
	 */
	private void ReWards() {
		RewardsDialog dialog = new RewardsDialog(PostDetailActivity.this, "提示：打赏开始",articleId);
		dialog.showDialog();
	}
	private void CancleCollect() {
		showLoadingDialog("取消收藏");
		Map<String, String> params=new HashMap<String,String>();
		params.put("user_id", ""+SetUtils.GetUserId(this));
		params.put("article_id", ""+articleId);
		HTTPUtils.post(this, Constance.URL.USER_UN_COLLECT, params, new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
				if(arg0!=null){
					dismissLoadingDialog();
					model.Praise uncollect = GsonUtils.parseJSON(arg0, model.Praise.class);
					Log.i("取消后的状态",uncollect.getStatus());
					if(uncollect.getStatus().equals(Constance.STATUS_TYPE.SUCCESS)){
						IsCollect=true;
						Drawable collect=getResources().getDrawable(R.drawable.ic_collect);  
						collect.setBounds(0, 0, collect.getMinimumWidth(), collect.getMinimumHeight());
						mTvCollect.setCompoundDrawables(null, collect, null, null);
					}
				}
			}
			@Override
			public void onErrorResponse(VolleyError arg0) {
				showToast("解析失败");
			}
		});
	}
	private void Collecting() {
		showLoadingDialog("收藏成功");
		Map<String, String> params=new HashMap<String,String>();
		params.put("user_id", ""+SetUtils.GetUserId(this));
		params.put("article_id", ""+articleId);
		HTTPUtils.post(this, Constance.URL.USER_COLLECT, params, new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
				if(arg0!=null){
					dismissLoadingDialog();
					model.Praise uncollect = GsonUtils.parseJSON(arg0, model.Praise.class);
					if(uncollect.getStatus().equals(Constance.STATUS_TYPE.SUCCESS)){
						IsCollect=false;
						Drawable collect=getResources().getDrawable(R.drawable.ic_collects);  
						collect.setBounds(0, 0, collect.getMinimumWidth(), collect.getMinimumHeight());
						mTvCollect.setCompoundDrawables(null, collect, null, null);
					}
				}
			}
			@Override
			public void onErrorResponse(VolleyError arg0) {
				
			}
		});
	}
	private void BaseShare(){
		
	}
	/**
	 * 微信分享
	 */
	private void ShareWx() {
		 BaseShare();
		 new ShareAction(this).setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE).setCallback(umShareListener)
         .withText("社区吧祝大家新年快乐！")
         .withMedia(music)
         .share();
	}
	private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(PostDetailActivity.this, platform + " 分享成功啦", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(PostDetailActivity.this,platform + " 分享失败啦", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(PostDetailActivity.this,platform + " 分享取消了", Toast.LENGTH_SHORT).show();
        }
    };
    private ShareBoardlistener shareBoardlistener = new ShareBoardlistener() {

        @Override
        public void onclick(SnsPlatform snsPlatform,SHARE_MEDIA share_media) {
            new ShareAction(PostDetailActivity.this).setPlatform(share_media).setCallback(umShareListener)
                    .withText("多平台分享")
                    .share();
        }
    };
	private Button mBtnPic;
	private LinearLayout mLlPic;
	private RelativeLayout mRtlPic;
	private PasteEditText mEtInput;
	private TextView mTvSend;
	private Button mBtnVoice;
	private TextView mTvVoice;
	/**
	 * qq空间分享
	 */

	private void ShareQqzone() {
		 new ShareAction(this).setPlatform(SHARE_MEDIA.QZONE).setCallback(umShareListener)
         .withText("hello umeng")
         .withMedia(image)
         .share();
		 share_view.setVisibility(View.GONE);
	}

	/**
	 * qq好友分享
	 */
	private void ShareQq() {
		 new ShareAction(this).setPlatform(SHARE_MEDIA.QQ).setCallback(umShareListener)
         .withText(shareContent)
         .withMedia(music)
         .withTitle("qqshare")
         .withTargetUrl("http://dev.umeng.com")
         .share();
		 share_view.setVisibility(View.GONE);
	}

	private void ShareWb() {
		new ShareAction(this).setPlatform(SHARE_MEDIA.SINA).setCallback(umShareListener)
        .withText(shareContent)
//        .withTargetUrl("http://www.baidu.com")
        .withMedia(image)
        .share();
		share_view.setVisibility(View.GONE);
	}

	private void Share() {
		share_view.setVisibility(View.VISIBLE);
	}
	/**
	 * 点赞
	 */
	private void Praise() {
		showLoadingDialog("正在点赞");
		Map<String, String> params=new HashMap<String,String>();
		params.put("user_id", ""+SetUtils.GetUserId(this));
		params.put("article_id", ""+articleId);
		HTTPUtils.post(this, Constance.URL.USER_PRAISE, params, new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
				if(arg0!=null){
					dismissLoadingDialog();
					 model.Praise praise = GsonUtils.parseJSON(arg0,model.Praise.class);
					 Log.i("点赞后的状态", praise.getStatus());
					 if(praise.getStatus().equals(Constance.STATUS_TYPE.SUCCESS)){
						 IsPraise=false;
					 }
					Drawable Praised=getResources().getDrawable(R.drawable.ic_praises);  
					Praised.setBounds(0, 0, Praised.getMinimumWidth(), Praised.getMinimumHeight());   
					mTvPraise.setCompoundDrawables(null, Praised, null, null);  
					mTvPraise.setText("点赞"+(NumPraise+1));
					switch (Zaned) {
					case Constance.STATUS_TYPE.SUCCESS:
						mTvPraise.setText("点赞"+(NumPraise+1));
						break;
					case Constance.STATUS_TYPE.ERROR:
						mTvPraise.setText("点赞"+(NumPraise));
						break;
					default:
						break;
					}
				}
			}
			@Override
			public void onErrorResponse(VolleyError arg0) {
			}
		});
	}
	/**
	 * 取消点赞
	 */
	private void CanclePraise() {
		showLoadingDialog("取消点赞");
		Map<String, String> params=new HashMap<String,String>();
		params.put("user_id", ""+SetUtils.GetUserId(this));
		params.put("article_id", ""+articleId);
		HTTPUtils.post(this, Constance.URL.USER_UN_PRAISE, params, new VolleyListener() {
			@Override
			public void onResponse(String arg0) {
				if(arg0!=null){
					dismissLoadingDialog();
					 model.Praise praise = GsonUtils.parseJSON(arg0, model.Praise.class);
					 Log.i("取消后的状态", praise.getStatus());
					 if(praise.getStatus().equals(Constance.STATUS_TYPE.SUCCESS)){
						 IsPraise=true;
					 }
					Drawable Praised=getResources().getDrawable(R.drawable.ic_praise);  
					Praised.setBounds(0, 0, Praised.getMinimumWidth(), Praised.getMinimumHeight());   
					mTvPraise.setCompoundDrawables(null, Praised, null, null);  
					switch (Zaned) {
					case Constance.STATUS_TYPE.SUCCESS:
						mTvPraise.setText("点赞"+NumPraise);
						break;
					case Constance.STATUS_TYPE.ERROR:
						mTvPraise.setText("点赞"+(NumPraise-1));
						break;
					default:
						break;
					}
				}
			}
			@Override
			public void onErrorResponse(VolleyError arg0) {
			}
		});
	}
	/**
	 * 更多
	 */
	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		
		if(arg2!=null){
			if (arg1 == 66) {
				showLoadingDialog("回复成功");
				GetPostDetail();
			} if (arg1 == 152) {
				showLoadingDialog("回复成功");
				GetPostDetail();
			} else {
				UMShareAPI.get(this).onActivityResult(arg0, arg1, arg2);
			}
		}
		super.onActivityResult(arg0, arg1, arg2);
	}
	@Override
	protected void onDestroy() {
		dismissLoadingDialog();
		super.onDestroy();
	}
	public class detail_other_post extends BaseAdapter {
		private Context context;
		private ArrayList<Comment> mOtherComment;
		private ViewHold viewHold;
		private PostDetailActivity activity;
		private PasteEditText mEtInput;
		private TextView mTvSend;
		private String TypeReply;
		private int articleId;
		private int ParentCommentId;
		public detail_other_post(Context context) {
			this.context = context;
			
		}
		public detail_other_post(Context context,PostDetailActivity activity, ArrayList<Comment> mOtherComment) {
			this.context = context;
			this.activity = activity;
			this.mOtherComment = mOtherComment;
		}
		public detail_other_post(Context context, PostDetailActivity postDetailActivity,
				ArrayList<Comment> mOtherComment, PasteEditText mEtInput, TextView mTvSend) {
					this.context = context;
					this.activity = postDetailActivity;
					this.mOtherComment = mOtherComment;
					this.mEtInput = mEtInput;
					this.mTvSend = mTvSend;
					
		}
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mOtherComment.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			final int pos=position;
			if(convertView==null){
				convertView=View.inflate(context, R.layout.item_detail_other_post, null);
				viewHold = new ViewHold();
				viewHold.list_each_other_post=(ListView) convertView.findViewById(R.id.list_each_other_post);
				viewHold.ImgPhoto=(ImageView) convertView.findViewById(R.id.img_photo);
				viewHold.TvName=(TextView) convertView.findViewById(R.id.tv_name);
				viewHold.TvName1=(TextView) convertView.findViewById(R.id.tv_name1);
				viewHold.TvTime=(TextView) convertView.findViewById(R.id.tv_time);
				viewHold.TvTime1=(TextView) convertView.findViewById(R.id.tv_time1);
				viewHold.TvList=(TextView) convertView.findViewById(R.id.tv_list);
				viewHold.TvComment=(TextView) convertView.findViewById(R.id.tv_comment);
				viewHold.TvComment1=(TextView) convertView.findViewById(R.id.tv_comment1);
				viewHold.TvReply=(TextView) convertView.findViewById(R.id.tv_reply);
				viewHold.LlChild=(LinearLayout) convertView.findViewById(R.id.ll_child);
				convertView.setTag(viewHold);
			}else {
				viewHold = (ViewHold) convertView.getTag();
			}	
			    if(mOtherComment.size()>0){
			    	viewHold.TvName.setText(mOtherComment.get(position).getUser().getNickname());
			    	viewHold.TvComment.setText(mOtherComment.get(position).getContent());
			    	if(mOtherComment.get(position).getUser().getProfileImg().startsWith("http")){
			    		UILUtils.displayImageNoAnim(mOtherComment.get(position).getUser().getProfileImg(), viewHold.ImgPhoto);
			    	}else {
			    		UILUtils.displayImageNoAnim(Constance.URL.IMG_BASE+mOtherComment.get(position).getUser().getProfileImg(), viewHold.ImgPhoto);
					}
			    	viewHold.TvTime.setText(mOtherComment.get(position).getCreatedAt());
			    	viewHold.TvList.setText(""+(position+1)+"楼");
			    	if(mOtherComment.get(position).getParentCommentId()!=0){
						viewHold.LlChild.setVisibility(View.VISIBLE);
					}else {
						viewHold.LlChild.setVisibility(View.GONE);
					}
			    	for (int i = 0; i < mOtherComment.size(); i++) {
						if(mOtherComment.get(i).getId().equals(mOtherComment.get(position).getParentCommentId())){
							viewHold.TvComment1.setText(mOtherComment.get(i).getContent());
							viewHold.TvName1.setText(mOtherComment.get(i).getUser().getNickname());
							viewHold.TvTime1.setText(mOtherComment.get(i).getCreatedAt());
						}
					}
			    	viewHold.TvReply.setOnClickListener(new OnClickListener() {
						private boolean IsReply;
						@Override
						public void onClick(View v) {
							ParentCommentId= mOtherComment.get(pos).getId();
							articleId = mOtherComment.get(pos).getArticleId();
							TypeReply="回复"+(position+1)+"楼"+mOtherComment.get(position).getUser().getNickname();
							mEtInput.setHint(TypeReply);
							ReplyOther();
						}
					});
			    	viewHold.ImgPhoto.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							if(SetUtils.islogined(context)){
								Intent intent = new Intent(context,MineActivity.class);
								intent.putExtra(Constance.INTENT.USER_ID, mOtherComment.get(position).getUser().getId());
								context.startActivity(intent);
							}else {
								context.startActivity(new Intent(context,LoginActivity.class));
							}
						}
					});
			    }
			return convertView;
		}
		class ViewHold{
			ListView list_each_other_post;
			ImageView ImgPhoto;
			TextView TvName;
			TextView TvName1;
			TextView TvTime;
			TextView TvTime1;
			TextView TvList;
			TextView TvComment;
			TextView TvComment1;
			TextView TvReply;
			LinearLayout LlChild;
		}	
		private void ReplyOther() {
			mTvSend.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					if(mEtInput.getHint().equals(TypeReply)){
						ReplyOthers();
						Toast.makeText(context, TypeReply, 1).show();
					}
				}
			});
		}
		/**

		 * 回复其他人

		 */
		private void ReplyOthers() {
			activity.showLoadingDialog();
			Map<String, String> params=new HashMap<String,String>();
			params.put("user_id",""+SetUtils.GetUserId(context));
			params.put("article_id",""+articleId);
			params.put("parent_comment_id", ""+ParentCommentId);
			params.put("content", mEtInput.getText().toString().trim());
			HTTPUtils.post(context, Constance.URL.REPLY_POST, params, new VolleyListener() {
				@Override
				public void onResponse(String arg0) {
					if(arg0!=null){
						activity.dismissLoadingDialog();
						Toast.makeText(context, "回复成功",1).show();
						GetPostDetail();
						srcollViewEx.measure(0, 0);
						mListImg.measure(0, 0);
						mListOtherPost.measure(0, 0);
						int height=srcollViewEx.getHeight()+mListImg.getHeight()+mListOtherPost.getHeight();
						srcollViewEx.scrollTo(0,height);  
						srcollViewEx.smoothScrollTo(0, height); 
					}
				}
				@Override
				public void onErrorResponse(VolleyError arg0) {
					Toast.makeText(context, "解析错误",1).show();
				}
			});
		}
	}

}
